// 引入配置
import {
  devBaseUrl,
  isDevProxy,
  proBaseUrl,
  contentType,
  timeout
} from "@/config";

let baseUrl = ''
if (process.env.NODE_ENV == "development") {
  if (isDevProxy) {
    baseUrl = '/api'
  } else {
    baseUrl = devBaseUrl
  }
} else {
  baseUrl = proBaseUrl
}

// 初始化请求配置
uni.$u.http.setConfig((defaultConfig) => {
  /* defaultConfig 为默认全局配置 */
  defaultConfig.baseURL = baseUrl
  defaultConfig.header['Content-Type'] = contentType
  defaultConfig.timeout = timeout * 1000
  return defaultConfig
})

module.exports = (vm) => {
  require('./requestInterceptors')(vm)
  require('./responseInterceptors')(vm)
}